package com.bianguo.android.assemblydemo;

import android.app.Application;

import com.bianguo.android.componentlib.AppConfig;
import com.bianguo.android.componentlib.IAppComponent;

public class BaseApplication extends Application implements IAppComponent {

    private static BaseApplication application;

    public static BaseApplication getApplication() {
        return application;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        initialization(this);
    }

    @Override
    public void initialization(Application app) {
        application = (BaseApplication) app;
        for (String component : AppConfig.COMPONENTS) {
            try {
                Class<?> clazz = Class.forName(component);
                Object object = clazz.newInstance();
                if (object instanceof IAppComponent) {
                    ((IAppComponent) object).initialization(this);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
